<template>
	<view>
		<view class="ceiling" :style="{ 'padding-top': statusBarHeight + 'px' }"></view>
		<!-- 顶部导航 开始 -->
		<selectHead left-button="买入" right-button="卖出" class="selectBox" :active-button="activeButton" @changeBtn="handleSelect">
			<view slot="left" @click="toHome()">
				<view class="" style="color: #FFFFFF;">主页</view>
			</view>
			<view slot="right">
				<view class="flex align-center" style="position: relative;">
					<view class="Tips end_top margin-left-xs" @click="tonavigateTo('/pages/public/search/search')" style="margin-right: 5rpx;position: absolute;left: -72rpx;">
						<image src="/static/images/search.png" mode="widthFix" style="width: 50rpx;"></image>
					</view>
					<view class="Tips end_top margin-left-xs" @click="tonavigateTo('/pages/public/msg/msg')">
						<image src="/static/images/msg.png" mode="widthFix" style="width: 50rpx;"></image>
					</view>
				</view>
			</view>
		</selectHead>
		<!-- 顶部导航 结束 -->
		
	
		<view  v-if="activeButton == '买入'">
			<view class="flex align-center border-bottom-1B202C padding" v-for="(item,index) in dataBuy" :key="index">
				<!-- <view class="text-blue text-xl">卖出</view> -->
				<view class="color_E23232 text-xl">买入</view>
				<view class="margin-left-sm flex-sub flex justify-between align-center">
					<view>
						<view class="text-lg text-black">{{item.sname}}</view>
						<view class="text-sm color_99A2B5 margin-top-sm">{{item.scode}}</view>
					</view>
					<view>
						<view class="text-lg text-black text-right">{{(item.balance) * parseFloat(item.smoney).toFixed(2)}}元</view>
						<view class="text-sm color_99A2B5 margin-top-sm text-right">{{item.atime}}</view>
					</view>
				</view>
			</view>
		</view>
		
		<view v-if="activeButton == '卖出'">
			<view class="flex align-center border-bottom-1B202C padding" v-for="(item,index) in dataSell" :key="index">
				<view class="text-blue text-xl">卖出</view>
				<!-- <view class="color_E23232 text-xl">买入</view> -->
				<view class="margin-left-sm flex-sub flex justify-between align-center">
					<view>
						<view class="text-lg text-black">{{item.sname}}</view>
						<view class="text-sm color_99A2B5 margin-top-sm">{{item.snum}}</view>
					</view>
					<view>
						<view class="text-lg text-black text-right">{{parseFloat(item.profitAndLoss).toFixed(2)}}元</view>
						<view class="text-sm color_99A2B5 margin-top-sm text-right">{{item.atime}}</view>
					</view>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	import selectHead from "@/component/selectHead/selectHead.vue"
	export default {
		components: {
			selectHead
		},
		data() {
			return {
				activeButton: "买入", //传入选中的button
				statusBarHeight: getApp().globalData.statusBarHeight, //状态栏高度
				
				dataBuy: [],
				dataSell: [],
				// dataHas: [],
			}
		},
		methods: {
			// 跳转页面
			tonavigateTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			// 到首页
			toHome: function() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			//返回上一页
			handleBack(){
				uni.navigateBack({
				    delta: 1
				});
			},
			//选择行情/自选
			handleSelect(type) {
				this.activeButton = type == 'left' ? '买入' : '卖出'
			},
			// 买入订单
			getBuy() {
				this.$Request.get(this.$api.index.getNewBuyByUser).then(res => {
					this.dataBuy = res.data;
				})
			},
			// 卖出订单
			getSell() {
				this.$Request.get(this.$api.index.getSellByUser).then(res => {
					this.dataSell = res.data;
				})
			},
			// 卖出订单
			// getHas() {
			// 	this.$Request.get(this.$api.index.getHas).then(res => {
			// 		this.dataHas = res.data;
			// 	})
			// },
		},
		onLoad(e) {
			if(e.type == 2){
				this.activeButton = '卖出'
			}
			this.getBuy()
			this.getSell()
			//this.getHas()
		}
	}
</script>

<style scoped>
	.selectBox{
		background-color: #EE515A;
	}
	.border-bottom-1B202C {
		border-color: #DDDDDD;
	}
</style>
